package example.exam.Shopee;

import java.util.LinkedList;

public class Demo6 {

    public static String replaceStr(String s) {
        char[] chars = s.toCharArray();
        LinkedList<Character> linkedList = new LinkedList<>();
        StringBuilder builder = new StringBuilder();
        for (char aChar : chars) {
            if (aChar >= '0' && aChar <= '9') {
                linkedList.addFirst(aChar);
            } else {
                boolean flag = true;
                while (linkedList.size() != 0) {
                    linkedList.removeLast();
                    flag = false;
                }
                if (!flag) {
                    builder.append("num");
                }
                builder.append(aChar);
            }
        }
        if (linkedList.size() != 0) {
            builder.append("num");
        }
        return builder.toString();
    }

    public static void main(String[] args) {
        System.out.println(replaceStr("abvhjb1y3ddd"));

        System.out.println(replaceStr("111"));

        System.out.println(replaceStr("abvhjb123ddd"));
    }
}
